//
//  CBJTabBarViewController.swift
//  Weibo
//
//  Created by 崔健 on 16/5/19.
//  Copyright © 2016年 cbj. All rights reserved.
//

import UIKit

class CBJTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabbar = CBJTabBarView()
        tabbar.plusBtn.addTarget(self, action: #selector(composeBtnClick), forControlEvents: .TouchUpInside)

        self.setValue(tabbar, forKey: "tabBar")
        setNavVc()
        
    }
    
    @objc private func composeBtnClick(){
        
        
        let composeView = CBJComposeView()
        
        composeView.showTarget(self)
        
        
//        composeView!.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
//        
//        UIApplication.sharedApplication().keyWindow?.addSubview(composeView!)
    }
    
    
    func  setNavVc() {
        
        self.setChildNavRootVc(CBJHomeViewController() , imageName: "tabbar_home" , title: "首页")
        
        self.setChildNavRootVc(CBJMessageViewController() , imageName: "tabbar_message_center" , title: "消息")
        self.setChildNavRootVc(CBJDiscoverViewController() , imageName: "tabbar_discover" , title: "发现")

        self.setChildNavRootVc(CBJProfileViewController() , imageName: "tabbar_profile" , title: "我")
    }
    
    func setChildNavRootVc(vc: UIViewController , imageName: String , title: String) {
      
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        vc.tabBarItem.title = title
        let navVc = CBJBaseNavController(rootViewController: vc)
        self.addChildViewController(navVc)
        
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -5)
    }
    

}
